<div class="fsh-rightPanel">
    <div class="layui-anim layui-anim-upbit">
        <div id="list_form" class="layui-form-item">
            <div class="layui-inline">
                <input type="text" id="_schoolCode" class="layui-input" name="schoolCode" readonly/>
            </div>
            <div class="layui-inline">
                <input id="_schoolName" name="schoolName1" class="layui-input" placeholder="请选择学校" autocomplete="off"
                       readonly/>
            </div>
            <div class="layui-inline">
                <button class="layui-btn btn-primary" id="btn-search">搜索</button>
            </div>
        </div>
        <div>
            <div class="layui-btn-container layui-inline" style="text-align: left;">
                <button class="layui-btn" id="btn-expand">全部展开</button>
                <button class="layui-btn" id="btn-fold">全部折叠</button>
                <button class="layui-btn" id="btn-refresh">刷新表格</button>
            </div>
            <div class="layui-btn-container layui-inline" style="float: right;">
                <button class="layui-btn btn-primary" id="btnAdd">新建</button>
            </div>
        </div>
        <table id="treeTable_speciality"></table>
    </div>
</div>
<!-- 表格状态列 -->
<script type="text/html" id="demoTreeTableState123123">
    <input type="checkbox" lay-filter="ckState" value="1" lay-skin="switch"
           lay-text="正常|锁定" checked/>
</script>
<script>
    layui.use(['table', 'treeTable'], function () {
        var $ = layui.jquery;
        var treeTable = layui.treeTable;
        var tableObj_source = {};
        // 渲染表格
        var renderTable = function () {
            tableObj_source = treeTable.render({
                elem: '#treeTable_speciality',
                // treeColIndex: 0,
                tree: {
                    iconIndex: 0,
                    isPidData: true,
                    idName: 'speciality_id',
                    pidName: 'pid'
                    //,childName: "childName"
                },
                // treeSpid: 0,//最上级的父级id
                // treeDefaultClose: true,
                text: {none: "<div style=\"padding: 18px 0;\">哎呀，一条数据都没有~</div>"},
                reqData: function (data, callback) {
                    var param = {page: 1, pageSize: 20};
                    $.extend(param, util.getFormData("list_form"));
                    $.get(context + "/api/eduSchoolSpeciality/list", param, function (res) {
                        callback(res.data);
                        layer.closeAll('loading');
                    });
                },
                cols: [
                    // {type: 'numbers'},
                    // {type: 'checkbox'},
                    {field: 'title', title: '名称'},
                    {field: "schoolCode", title: '学校代码'},
                    {field: "sort", title: '排序', width: 100},
                    {title: '操作', width: 200, align: 'center', unresize: true,
                        templet: function (d) {
                            return '<a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="update">修改</a>'
                                + '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                        }
                    }
                ]
            });
        };
        renderTable();

        $('#btn-expand').click(function () {treeTable.expandAll('#treeTable_speciality');});
        $('#btn-fold').click(function () {treeTable.foldAll('#treeTable_speciality');});
        $('#btn-refresh').click(function () {renderTable();});
        $('#btn-search').click(function () {reloadTable(tableObj_source);});

        // 添加
        $("#btnAdd").click(function () {
            showDialog({
                formId: 'add_form_Speciality',
                title: '新建'
                , template: 'add'
                , tableObj: tableObj_source
                , saveUrl: context + '/api/eduSchoolSpeciality/add'
                , type: 'POST'
                , dataType: 'json'
            })
        });

        //表格内部操作按钮监听
        treeTable.on('tool(treeTable_speciality)', function (obj) { //注：tool是工具条事件名，mainList是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            console.log(layEvent);
            if (layEvent === 'update') {
                showDialog({
                    formId: "add_form_Speciality"
                    , title: '编辑'
                    , template: 'add'
                    , tableObj: tableObj_source
                    , htmlData: data
                    , saveUrl: context + '/api/eduSchoolSpeciality/update'
                    , type: 'PATCH'
                    , dataType: 'json'
                })
            } else if (layEvent === 'del') {
                confirmDel("", tableObj_source);
            }
        });
        selectSchool();
    });
</script>
